import { http } from "@/utils/http";

/** 固件模型定义 */
export type FirmwareModel = {
  id: number;
  name: string;
  productId: number;
  version: string;
  part: string;
  remark: string;
  fileMd5: string;
  fileUrl: string;
  whereAt: number;
  appFileId: number | null;
  image: string;
  createdAt: string;
  updatedAt: string;
};

/** 分页获取固件列表 */
export const getFirmwareListApi = (data: IReqPagerData) => {
  return http.request<Resp<IRespPagerData<FirmwareModel>>>(
    "get",
    "/firmware/page-list",
    { params: data }
  );
};

/** 新增固件 */
export const addFirmwareApi = (data: Partial<FirmwareModel>) => {
  return http.request<Resp<null>>("post", "/firmware", { data });
};

/** 更新固件 */
export const updateFirmwareApi = (id: number, data: Partial<FirmwareModel>) => {
  return http.request<Resp<null>>("put", `/firmware/${id}`, { data });
};

/** 删除固件 */
export const deleteFirmwareApi = (id: number) => {
  return http.request<Resp<null>>("delete", `/firmware/${id}`);
};

/** 根据ID获取固件详情 */
export const getFirmwareByIdApi = (id: number) => {
  return http.request<Resp<{
    info: FirmwareModel
  }>>('get', '/firmware/getOne', {
    params: { id }
  });
};

/** 获取固件选项列表 */
export const getFirmwareOptionsApi = (params?: { fieldKey?: string; fieldLabel?: string; productId?: number }) => {
  return http.request<Resp<{
    options: Array<{
      label: string;
      val: string | number;
    }>
  }>>('get', '/firmware/getOptions', { params });
};
